package com.yangjie.common.service;

import java.io.Serializable;
import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.transaction.annotation.Transactional;

import com.yangjie.common.dao.Dao;
import com.yangjie.common.dao.criteria.PaginationQueryCriteria;
import com.yangjie.common.dao.criteria.QueryCriteria;

public abstract class AbstractService<T> implements Service {
	Logger logger = Logger.getLogger(this.getClass());
	public abstract Dao getDao();
	

	
	public void create(Object t) {
		logger.debug("create:" + t.toString());
		getDao().create(t);
		
	}

	@Override
	public Object get(Serializable id) {
		// TODO Auto-generated method stub
		return getDao().get(id);
	}


	public List<T> getAll() {
		// TODO Auto-generated method stub
		
		List<T> retval =  getDao().getAll();
		logger.debug("get all..............." + retval.size());
		return retval;
	}

	@Override
	public void update(Object t) {
		// TODO Auto-generated method stub
		getDao().update(t);
	}

	
	public void delete(Object t) {
		getDao().delete(t);
		
	}

	@Override
	public void deleteById(Serializable id) {
		// TODO Auto-generated method stub
		getDao().deleteById(id);
	}

	@Override
	public void deleteAll() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public long count() {
		// TODO Auto-generated method stub
		return 0;
	}
	
	public long count(QueryCriteria criteria) {
		// TODO Auto-generated method stub
		return getDao().count(criteria);
	}
	
	public long count(PaginationQueryCriteria criteria) {
		return getDao().count(criteria);
	}

	@Override
	public boolean exists(Serializable id) {
		// TODO Auto-generated method stub
		return false;
	}
	
	public List<T> find(QueryCriteria criteria) {
		return getDao().find(criteria);
	}
	
	public List<T> find(PaginationQueryCriteria criteria) {
		return getDao().find(criteria);
	}
}
